package com.usian.article.controller;

import com.usian.api.article.ApAuthorControllerApi;
import com.usian.article.service.ApAuthorService;
import com.usian.model.article.pojos.ApAuthor;
import com.usian.model.common.dtos.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/author")
public class ApAuthorController implements ApAuthorControllerApi {
    @Autowired
    private ApAuthorService apAuthorService;


    //保存作者信息
    @PostMapping("save")
    @Override
    public ResponseResult saveApAuthor(@RequestBody ApAuthor apAuthor) {
        return apAuthorService.saveApAuthor(apAuthor);
    }
    //根据用户id查询作者信息
    @GetMapping("/findByUserId/{id}")
    @Override
    public ApAuthor findByUserId(@PathVariable("id") Integer userId) {
        return apAuthorService.findByUserId(userId);
    }


    /*
    * admin远程调用根据用户名查询作者对象
    * */

    @Override
    @GetMapping("findByUserName/{name}")
    public ApAuthor findByUserName(@PathVariable String name) {
        return apAuthorService.findByUserName(name);
    }



    @Override
    @GetMapping("findByWmUserId/{id}")
    public ApAuthor findByWmUserId(@PathVariable Integer userId) {
        return apAuthorService.findByWmUserId(userId);
    }

    /**
     * 根据Id查询作者
     * 给user远程调用
     * @param id
     * @return
     */
    @Override
    @GetMapping("/findById/{id}")
    public ApAuthor findById(@PathVariable Integer id) {

        return apAuthorService.getById(id);
    }
}
